grammar CSV;

file: hdr row+;
hdr: row;

row: field (',' field)* '\r'? '\n';
field
    :   TEXT        # text
    |   STRING      # string
    |               # empty
    ;

TEXT:   ~[,\n\r"]+;
STRING: '"' ('""' | ~'"')* '"'; // quote-quote is an escaped quote. To get a double quote inside a double-quoted string,
// the CSV format generally uses two double quotes in a row.